import cv2
import numpy as np
import time

# 画面的高和宽
width, height = 200, 200
# 圆的半径
r = 20
# 起始坐标
x = r + 20
y = r + 100
# 每一帧的移动速度
x_offer = y_offer = 4

while cv2.waitKey(1) == -1:
    if x > width - r or x < r:
        x_offer *= -1
    if y > height - r or y < r:
        y_offer *= -1
    x += x_offer
    y += y_offer
    img = np.ones((width, height, 3), np.uint8) * 255
    cv2.circle(img, (x, y), r, (0, 0, 255), -1)
    cv2.imshow('img', img)
    time.sleep(1 / 60)

cv2.destroyAllWindows()
